'use strict';
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { INTEGER, TINYINT } = app.Sequelize;
    const UserPostLike = app.model.define(
        'UserPostLike',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            post_id: INTEGER,
            user_id: INTEGER,
            status: {type: TINYINT, defaultValue: 1}, // 1:正常 0:已取消
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'user_post_like',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    UserPostLike.associate = function() {
        app.model.Business.UserPostLike.belongsTo(app.model.Business.UserPost, {as: 'post', foreignKey: 'post_id'});
        app.model.Business.UserPostLike.belongsTo(app.model.Business.User, {as: 'user', foreignKey: 'user_id'});
    }

    return UserPostLike;
};
